<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Module: ActiveScaffold::Actions::Nested::ChildMethods</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../../../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Module</strong></td>
          <td class="class-name-in-header">ActiveScaffold::Actions::Nested::ChildMethods</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../../../files/vendor/plugins/active_scaffold/lib/actions/nested_rb.html">
                vendor/plugins/active_scaffold/lib/actions/nested.rb
                </a>
        <br />
            </td>
        </tr>

        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">



   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000306">add_existing</a>&nbsp;&nbsp;
      <a href="#M000308">after_create_save</a>&nbsp;&nbsp;
      <a href="#M000307">destroy_existing</a>&nbsp;&nbsp;
      <a href="#M000310">do_add_existing</a>&nbsp;&nbsp;
      <a href="#M000311">do_destroy_existing</a>&nbsp;&nbsp;
      <a href="#M000304">included</a>&nbsp;&nbsp;
      <a href="#M000309">nested_action_from_params</a>&nbsp;&nbsp;
      <a href="#M000305">new_existing</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">





      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Class methods</h3>

      <div id="method-M000304" class="method-detail">
        <a name="M000304"></a>

        <div class="method-heading">
          <a href="#M000304" class="method-signature">
          <span class="method-name">included</span><span class="method-args">(base)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000304-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000304-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/active_scaffold/lib/actions/nested.rb, line 109</span>
109:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">included</span>(<span class="ruby-identifier">base</span>)
110:       <span class="ruby-keyword kw">super</span>
111:       <span class="ruby-comment cmt"># This .verify method call is clashing with other non .add_existing actions. How do we do this correctly? Can we make it action specific.</span>
112:       <span class="ruby-comment cmt"># base.verify :method =&gt; :post,</span>
113:       <span class="ruby-comment cmt">#             :only =&gt; :add_existing,</span>
114:       <span class="ruby-comment cmt">#             :redirect_to =&gt; { :action =&gt; :index }</span>
115:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000306" class="method-detail">
        <a name="M000306"></a>

        <div class="method-heading">
          <a href="#M000306" class="method-signature">
          <span class="method-name">add_existing</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000306-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000306-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/active_scaffold/lib/actions/nested.rb, line 134</span>
134:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">add_existing</span>
135:       <span class="ruby-identifier">do_add_existing</span>
136: 
137:       <span class="ruby-identifier">respond_to</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">type</span><span class="ruby-operator">|</span>
138:         <span class="ruby-identifier">type</span>.<span class="ruby-identifier">html</span> <span class="ruby-keyword kw">do</span>
139:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">successful?</span>
140:             <span class="ruby-identifier">flash</span>[<span class="ruby-identifier">:info</span>] = <span class="ruby-identifier">as_</span>(<span class="ruby-value str">'Created %s'</span>, <span class="ruby-ivar">@record</span>.<span class="ruby-identifier">to_label</span>)
141:             <span class="ruby-identifier">return_to_main</span>
142:           <span class="ruby-keyword kw">else</span>
143:             <span class="ruby-identifier">render</span>(<span class="ruby-identifier">:action</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'add_existing_form'</span>, <span class="ruby-identifier">:layout</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">true</span>)
144:           <span class="ruby-keyword kw">end</span>
145:         <span class="ruby-keyword kw">end</span>
146:         <span class="ruby-identifier">type</span>.<span class="ruby-identifier">js</span> <span class="ruby-keyword kw">do</span>
147:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">successful?</span>
148:             <span class="ruby-identifier">render</span> <span class="ruby-identifier">:action</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'add_existing'</span>, <span class="ruby-identifier">:layout</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">false</span>
149:           <span class="ruby-keyword kw">else</span>
150:             <span class="ruby-identifier">render</span> <span class="ruby-identifier">:action</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'form_messages.rjs'</span>, <span class="ruby-identifier">:layout</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">false</span>
151:           <span class="ruby-keyword kw">end</span>
152:         <span class="ruby-keyword kw">end</span>
153:         <span class="ruby-identifier">type</span>.<span class="ruby-identifier">xml</span> { <span class="ruby-identifier">render</span> <span class="ruby-identifier">:xml</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">response_object</span>.<span class="ruby-identifier">to_xml</span>, <span class="ruby-identifier">:content_type</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-constant">Mime</span><span class="ruby-operator">::</span><span class="ruby-constant">XML</span>, <span class="ruby-identifier">:status</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">response_status</span> }
154:         <span class="ruby-identifier">type</span>.<span class="ruby-identifier">json</span> { <span class="ruby-identifier">render</span> <span class="ruby-identifier">:text</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">response_object</span>.<span class="ruby-identifier">to_json</span>, <span class="ruby-identifier">:content_type</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-constant">Mime</span><span class="ruby-operator">::</span><span class="ruby-constant">JSON</span>, <span class="ruby-identifier">:status</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">response_status</span> }
155:         <span class="ruby-identifier">type</span>.<span class="ruby-identifier">yaml</span> { <span class="ruby-identifier">render</span> <span class="ruby-identifier">:text</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">response_object</span>.<span class="ruby-identifier">to_yaml</span>, <span class="ruby-identifier">:content_type</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-constant">Mime</span><span class="ruby-operator">::</span><span class="ruby-constant">YAML</span>, <span class="ruby-identifier">:status</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">response_status</span> }
156:       <span class="ruby-keyword kw">end</span>
157:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000307" class="method-detail">
        <a name="M000307"></a>

        <div class="method-heading">
          <a href="#M000307" class="method-signature">
          <span class="method-name">destroy_existing</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000307-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000307-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/active_scaffold/lib/actions/nested.rb, line 159</span>
159:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">destroy_existing</span>
160:       <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">redirect_to</span>(<span class="ruby-identifier">params</span>.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">:action</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">:delete</span>)) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">request</span>.<span class="ruby-identifier">get?</span>
161: 
162:       <span class="ruby-identifier">do_destroy_existing</span>
163: 
164:       <span class="ruby-identifier">respond_to</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">type</span><span class="ruby-operator">|</span>
165:         <span class="ruby-identifier">type</span>.<span class="ruby-identifier">html</span> <span class="ruby-keyword kw">do</span>
166:           <span class="ruby-identifier">flash</span>[<span class="ruby-identifier">:info</span>] = <span class="ruby-identifier">as_</span>(<span class="ruby-value str">'Deleted %s'</span>, <span class="ruby-ivar">@record</span>.<span class="ruby-identifier">to_label</span>)
167:           <span class="ruby-identifier">return_to_main</span>
168:         <span class="ruby-keyword kw">end</span>
169:         <span class="ruby-identifier">type</span>.<span class="ruby-identifier">js</span> { <span class="ruby-identifier">render</span>(<span class="ruby-identifier">:action</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'destroy.rjs'</span>, <span class="ruby-identifier">:layout</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">false</span>) }
170:         <span class="ruby-identifier">type</span>.<span class="ruby-identifier">xml</span> { <span class="ruby-identifier">render</span> <span class="ruby-identifier">:xml</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">successful?</span> <span class="ruby-value">? </span><span class="ruby-value str">&quot;&quot;</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">response_object</span>.<span class="ruby-identifier">to_xml</span>, <span class="ruby-identifier">:content_type</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-constant">Mime</span><span class="ruby-operator">::</span><span class="ruby-constant">XML</span>, <span class="ruby-identifier">:status</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">response_status</span> }
171:         <span class="ruby-identifier">type</span>.<span class="ruby-identifier">json</span> { <span class="ruby-identifier">render</span> <span class="ruby-identifier">:text</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">successful?</span> <span class="ruby-value">? </span><span class="ruby-value str">&quot;&quot;</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">response_object</span>.<span class="ruby-identifier">to_json</span>, <span class="ruby-identifier">:content_type</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-constant">Mime</span><span class="ruby-operator">::</span><span class="ruby-constant">JSON</span>, <span class="ruby-identifier">:status</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">response_status</span> }
172:         <span class="ruby-identifier">type</span>.<span class="ruby-identifier">yaml</span> { <span class="ruby-identifier">render</span> <span class="ruby-identifier">:text</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">successful?</span> <span class="ruby-value">? </span><span class="ruby-value str">&quot;&quot;</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">response_object</span>.<span class="ruby-identifier">to_yaml</span>, <span class="ruby-identifier">:content_type</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-constant">Mime</span><span class="ruby-operator">::</span><span class="ruby-constant">YAML</span>, <span class="ruby-identifier">:status</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">response_status</span> }
173:       <span class="ruby-keyword kw">end</span>
174:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000305" class="method-detail">
        <a name="M000305"></a>

        <div class="method-heading">
          <a href="#M000305" class="method-signature">
          <span class="method-name">new_existing</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000305-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000305-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/active_scaffold/lib/actions/nested.rb, line 117</span>
117:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">new_existing</span>
118:       <span class="ruby-identifier">do_new</span>
119: 
120:       <span class="ruby-identifier">respond_to</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">type</span><span class="ruby-operator">|</span>
121:         <span class="ruby-identifier">type</span>.<span class="ruby-identifier">html</span> <span class="ruby-keyword kw">do</span>
122:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">successful?</span>
123:             <span class="ruby-identifier">render</span>(<span class="ruby-identifier">:action</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'add_existing_form'</span>, <span class="ruby-identifier">:layout</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">true</span>)
124:           <span class="ruby-keyword kw">else</span>
125:             <span class="ruby-identifier">return_to_main</span>
126:           <span class="ruby-keyword kw">end</span>
127:         <span class="ruby-keyword kw">end</span>
128:         <span class="ruby-identifier">type</span>.<span class="ruby-identifier">js</span> <span class="ruby-keyword kw">do</span>
129:           <span class="ruby-identifier">render</span>(<span class="ruby-identifier">:partial</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'add_existing_form'</span>, <span class="ruby-identifier">:layout</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">false</span>)
130:         <span class="ruby-keyword kw">end</span>
131:       <span class="ruby-keyword kw">end</span>
132:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <h3 class="section-bar">Protected Instance methods</h3>

      <div id="method-M000308" class="method-detail">
        <a name="M000308"></a>

        <div class="method-heading">
          <a href="#M000308" class="method-signature">
          <span class="method-name">after_create_save</span><span class="method-args">(record)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000308-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000308-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/active_scaffold/lib/actions/nested.rb, line 178</span>
178:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">after_create_save</span>(<span class="ruby-identifier">record</span>)
179:       <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">params</span>[<span class="ruby-identifier">:association_macro</span>] <span class="ruby-operator">==</span> <span class="ruby-identifier">:has_and_belongs_to_many</span>
180:         <span class="ruby-identifier">params</span>[<span class="ruby-identifier">:associated_id</span>] = <span class="ruby-identifier">record</span>
181:         <span class="ruby-identifier">do_add_existing</span>
182:       <span class="ruby-keyword kw">end</span>
183:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000310" class="method-detail">
        <a name="M000310"></a>

        <div class="method-heading">
          <a href="#M000310" class="method-signature">
          <span class="method-name">do_add_existing</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
The actual &quot;<a href="ChildMethods.html#M000306">add_existing</a>&quot;
algorithm
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000310-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000310-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/active_scaffold/lib/actions/nested.rb, line 190</span>
190:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">do_add_existing</span>
191:       <span class="ruby-identifier">parent_model</span>, <span class="ruby-identifier">id</span>, <span class="ruby-identifier">association</span> = <span class="ruby-identifier">nested_action_from_params</span>
192:       <span class="ruby-identifier">parent_record</span> = <span class="ruby-identifier">find_if_allowed</span>(<span class="ruby-identifier">id</span>, <span class="ruby-identifier">:update</span>, <span class="ruby-identifier">parent_model</span>)
193:       <span class="ruby-ivar">@record</span> = <span class="ruby-identifier">active_scaffold_config</span>.<span class="ruby-identifier">model</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">params</span>[<span class="ruby-identifier">:associated_id</span>])
194:       <span class="ruby-identifier">parent_record</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">association</span>) <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-ivar">@record</span>
195:       <span class="ruby-identifier">parent_record</span>.<span class="ruby-identifier">save</span>
196:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000311" class="method-detail">
        <a name="M000311"></a>

        <div class="method-heading">
          <a href="#M000311" class="method-signature">
          <span class="method-name">do_destroy_existing</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000311-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000311-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/active_scaffold/lib/actions/nested.rb, line 198</span>
198:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">do_destroy_existing</span>
199:       <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">active_scaffold_config</span>.<span class="ruby-identifier">nested</span>.<span class="ruby-identifier">shallow_delete</span>
200:         <span class="ruby-identifier">parent_model</span>, <span class="ruby-identifier">id</span>, <span class="ruby-identifier">association</span> = <span class="ruby-identifier">nested_action_from_params</span>
201:         <span class="ruby-ivar">@record</span> = <span class="ruby-identifier">find_if_allowed</span>(<span class="ruby-identifier">id</span>, <span class="ruby-identifier">:update</span>, <span class="ruby-identifier">parent_model</span>)
202:         <span class="ruby-identifier">collection</span> = <span class="ruby-ivar">@record</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">association</span>)
203:         <span class="ruby-identifier">assoc_record</span> = <span class="ruby-identifier">collection</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">params</span>[<span class="ruby-identifier">:id</span>])
204:         <span class="ruby-identifier">collection</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">assoc_record</span>)
205:       <span class="ruby-keyword kw">else</span>
206:         <span class="ruby-identifier">do_destroy</span>
207:       <span class="ruby-keyword kw">end</span>
208:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000309" class="method-detail">
        <a name="M000309"></a>

        <div class="method-heading">
          <a href="#M000309" class="method-signature">
          <span class="method-name">nested_action_from_params</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000309-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000309-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/active_scaffold/lib/actions/nested.rb, line 185</span>
185:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">nested_action_from_params</span>
186:       <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">params</span>[<span class="ruby-identifier">:parent_model</span>].<span class="ruby-identifier">constantize</span>, <span class="ruby-identifier">nested_parent_id</span>, <span class="ruby-identifier">params</span>[<span class="ruby-identifier">:parent_column</span>]
187:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>